<template>
  <div id="app">
    <!-- <div class="iconfont icon-toast_chenggong"></div> -->
    <transition name="slide">
      <Toast v-show="isShowToast"></Toast>
    </transition>
    <TopBar :key="topbarKeyValue"></TopBar>
    <Header></Header>
    <router-view @updateKey="updateKeyFn" />
    <Footer></Footer>
    <Login v-show="isShowLoginModal"></Login>
  </div>
</template>

<script>
import TopBar from '@/components/TopBar';
import Header from '@/components/Header';
import Footer from '@/components/Footer';
import Login from '@/components/Login';
import Toast from '@/components/Toast';
import { mapState } from 'vuex';
// import axios from 'axios';
import axios from '@/request/request';
import { JingpinAPI } from '@/request/api';
export default {
  components: {
    TopBar,
    Header,
    Footer,
    Login,
    Toast,
  },
  data() {
    return {
      topbarKeyValue: 0,
    };
  },
  watch: {
    //希望每次切换路由时,都让tobBar重新加载(方法二)
    '$route.path': {
      handler(newVal, oldVal) {
        if (newVal != oldVal) {
          this.topbarKeyValue++;
        }
      },
    },
  },
  async created() {
    let res = await JingpinAPI();
    console.log(res);

    axios.get('/products/recommend').then((res) => {
      // console.log('请求成功', res);
    });
    console.log(process.env.VUE_APP_BASE_URL);
  },
  computed: {
    ...mapState({
      isShowLoginModal: (state) => state.showModal.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  methods: {
    updateKeyFn() {
      console.log('updateKeyFn');
      this.topbarKeyValue++;
    },
  },
};
</script>

<style lang="less">
/* 入场的起始状态 = 离场的结束状态 */
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
